package com.itbaizhan.controller;

import com.itbaizhan.daomain.Student;
import com.itbaizhan.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;


@Controller
@RequestMapping("/student")
public class StudentController {

    @Autowired
    private StudentService studentService;
    //将数据放进model模型中，在jsp页面中显示
    @RequestMapping("/all")
    public String all(Model model){
        List<Student> students = studentService.findAll();
        model.addAttribute("students",students);
        return "allstudent";
    }
    /*添加学生后，重定向返回查询所有学生，在jsp页面显示*/
    @RequestMapping("/add")
    public String add(Student student){
        studentService.addStudent(student);
        //重定向返回查询所有学生
        return "redirect:/student/all";
    }
}
/*启动整个项目，启动父工程，配置tomcat7:run*/